
import pandas as pd
import prince

pd.set_option('display.float_format', lambda x: '{:.6f}'.format(x))
X = pd.DataFrame(data=[
    [326, 38, 241, 110, 3],
    [688, 116, 584, 188, 4],
    [343, 84, 909, 412, 26],
    [98, 48, 403, 681, 85]],
    columns=pd.Series(['Fair', 'Red', 'Medium', 'Dark', 'Black']),
    index=pd.Series(['Blue', 'Light', 'Medium', 'Dark'])
)
print(X)

ca = prince.CA(n_components=2,
               n_iter=3,
               copy=True,
               check_input=True,
               engine='auto',
               random_state=42
               )
X.columns.rename('Hair color', inplace=True)
X.index.rename('Eye color', inplace=True)
ca = ca.fit(X)

x_row = ca.row_coordinates(X)
print(x_row)

x_column = ca.column_coordinates(X)
print(x_column)

ax = ca.plot_coordinates(X=X,
                         ax=None,
                         figsize=(6, 6),
                         x_component=0,
                         y_component=1,
                         show_row_labels=True,
                         show_col_labels=True
                         )
ax.get_figure().savefig('images/ca_coordinates.svg')
